﻿using System;
using System.Linq;
using System.Windows.Controls;
using System.Windows;
using System.Windows.Input;

namespace ForumsBrowser
{
    public class FasterScrollingFlowDocumentScrollViewer : FlowDocumentScrollViewer
    {
        public static readonly DependencyProperty ScrollFactorProperty =
            DependencyProperty.Register("ScrollFactor", typeof(int), typeof(FasterScrollingFlowDocumentScrollViewer), new PropertyMetadata(1));

        public int ScrollFactor
        {
            get
            {
                return (int)this.GetValue(ScrollFactorProperty);
            }
            set
            {
                this.SetValue(ScrollFactorProperty, value);
            }
        }

        protected override void OnMouseWheel(System.Windows.Input.MouseWheelEventArgs e)
        {
            // handle the case where the user is wanting to zoom in or out. 
            if ((Keyboard.Modifiers & ModifierKeys.Control) != ModifierKeys.Control)
            {
                for (int i = 0; i < ScrollFactor; i++)
                {
                    base.OnMouseWheel(e);
                    e.Handled = false;
                }
            }
            else
            {
                base.OnMouseWheel(e);
            }

            e.Handled = true;
        }
    }
}
